/**
 * Settings.java
 * Contains data needed by all objects.
 * 
 * Copyright (c) 2012 The Javanauts
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package edu.utsa.cs.cs4953_2012.abacus;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


/**
 * A place holder for data that's better off being global.
 * 
 */
public class Settings {
	/**
	 * Determines whether the board is in split-board mode or normal mode.
	 * 
	 */
	public enum Mode {
		NORMAL(400, "images/backgrounds_example_blue.png"), SPLIT(500, "images/backgrounds_example_stone.png");

		private int width;
		private BufferedImage background;

		private Mode(int width, String filename) {
			this.width = width;
			try {
				background = ImageIO.read(new File(filename));
			} catch (IOException e) {
				System.err.println(e.getMessage());
			}
		}

		/**
		 * Gets the horizontal offset a row should start at.
		 * 
		 * @param row
		 *            The row in question.
		 * @return The offset in pixels.
		 */
		public int getRowOffset(int row) {
			if (row < 0 || row >= 13)
				throw new IllegalArgumentException("Only rows 0-12 are valid.");
			if (this == NORMAL)
				return 4;
			switch (row) {
			case 0:
			case 1:
			case 2:
			case 6:
			case 7:
			case 8:
			case 12:
				return 4;
			case 3:
			case 4:
			case 5:
			case 9:
			case 10:
			case 11:
				return 4 + SPLIT.width - NORMAL.width;
			}
			return 4;
		}

		/**
		 * Gets the board width according to the current mode.
		 * 
		 * @return The width of the board in pixels.
		 */
		public int getWidth() {
			return width;
		}
		
		public BufferedImage getBackground() {
			return background;
		}
	}

	/**
	 * A reference to the board logic.
	 */
	public static Board board;
	/**
	 * The main window.
	 */
	public static Program program;
	/**
	 * Whether the board is drawn split or not.
	 */
	public static Mode mode;
	/**
	 * A reference to the mayan numeral panel.
	 */
	public static MayaNumeralPanel mayaPanel;
	/**
	 * A reference to the status panel.
	 */
	public static StatusPanel statusPanel;
	/**
	 * A reference to the drawing panel.
	 */
	public static DrawingPanel drawingpanel;
	/**
	 * Makes the Mayan Numeral Panel visible/invisible.
	 */
	public static void toggleMayanNumerals() {
		mayaPanel.setVisible(!mayaPanel.isVisible());
	}
	/**
	 * Makes the decimal Numeral Panel visible/invisible.
	 */
	public static void toggleStatusPanel() {
		statusPanel.setVisible(!statusPanel.isVisible());
	}
	/**
	 * Turns the maya numerals on or off.
	 * @param b Whether the panel should be visible.
	 */
	public static void setMayanNumerals(boolean b) {
		mayaPanel.setVisible(b);
	}
	/**
	 * Turns the decimal numerals on or off.
	 * @param b Whether the panel should be visible.
	 */
	public static void setStatusPanel(boolean b) {
		statusPanel.setVisible(b);
	}
	public static void setSound(boolean b){
		SoundEffect.soundOn = b;
	}
	/**
	 * A collection of all available bead sets loaded from memory.
	 */
	public static BeadSet[] beadset = new BeadSet[2];
	/**
	 * The index (in Settings.beadset[] of the currently active bead set.
	 */
	public static int currentBeadSet = 1;
}
